package com.bolt.core.view.components;

import com.bolt.common.utils.StrUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.Writer;

/**
 * 带结束标签的HTML元素
 * Created by michao on 2017/9/13.
 */
public abstract class ClosingUI extends  FormItem {

    String openTemplate;

    protected abstract String getDefaultOpenTemplate();

    public void setOpenTemplate(String openTemplate) {
        this.openTemplate = openTemplate;
    }


    @Override
    public void start(HttpServletRequest req, HttpServletResponse res, Writer writer) {
        try {
            evaluateParams(req);
            if(StrUtil.isNotBlank(getDefaultOpenTemplate())){
                mergeTemplate(req,res,writer,buildTemplateName( getDefaultOpenTemplate() ));
            }
        } catch (Exception e) {
            logger.error(e);
        }
    }

    @Override
    public void end(HttpServletRequest req, HttpServletResponse res, Writer writer) {
        try {
            mergeTemplate(req,res,writer,buildTemplateName( getDefaultTemplate() ));
        } catch (Exception e) {
            logger.error(e);
        }
    }

}
